//+------------------------------------------------------------------+
//|                                                       082502.mq5 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_minimum 1
#property indicator_maximum 10
#property indicator_buffers 4
#property indicator_plots   2
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_COLOR_LINE
#property indicator_color1  clrRed,clrBrown
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Label2
#property indicator_label2  "Label2"
#property indicator_type2   DRAW_COLOR_SECTION
#property indicator_color2  clrMediumVioletRed,clrMidnightBlue
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- indicator buffers
double         Label1Buffer[];
double         Label1Colors[];
double         Label2Buffer[];
double         Label2Colors[];
int ma5_h;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
   SetIndexBuffer(1,Label1Colors,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(2,Label2Buffer,INDICATOR_DATA);
   SetIndexBuffer(3,Label2Colors,INDICATOR_COLOR_INDEX);
ma5_h = iMA(NULL,PERIOD_CURRENT,5,0,MODE_SMA,PRICE_MEDIAN);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
//---
double ma5[];
CopyBuffer(ma5_h,0,0,rates_total,ma5);
int start = 0;
if(prev_calculated > 0) start = prev_calculated - 1;
for(int i = start; i<rates_total; i++)
{
   Label1Buffer[i] = ma5[i];
   
}
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
